package demo;

import java.io.*;
import java.net.*;

public class GameServer {
	private ServerSocket ss = null;

	private Socket socket = null;

	public static void main(String[] args) {

		new GameServer();
	}

	public GameServer() {

		try {

			if (ss == null)
				ss = new ServerSocket(8888);

			System.out.println("====服务器启动====");

			while (ss != null) {

				try {
					while (true) {
						socket = ss.accept();
						new Thread(new DataDisposeThread(socket)).start();
						System.out.println("----客户端上线----");
					}
					// socket = ss.accept();
					// System.out.println("----客户端上线----");
					// new Thread(new DataDisposeThread(socket)).start();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}

		} catch (IOException e) {

			try {

				if (ss != null)
					ss.close();

				if (socket != null)
					socket.close();

			} catch (IOException er) {

				er.printStackTrace();
			}

			e.printStackTrace();

		}
	}
}
